/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachineroster.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import warmachineroster.RosterElement;
import warmachineroster.WarcasterRosterElement;
import warmachineroster.WarjackRosterElement;
import warmachineroster.WarmachineRosterPackage;
import warmachinesystem.Warcaster;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Warcaster Roster Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachineroster.impl.WarcasterRosterElementImpl#getBattlegroup <em>Battlegroup</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class WarcasterRosterElementImpl extends RosterElementImpl implements WarcasterRosterElement {
	/**
	 * The cached value of the '{@link #getBattlegroup() <em>Battlegroup</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBattlegroup()
	 * @generated
	 * @ordered
	 */
	protected EList<WarjackRosterElement> battlegroup;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WarcasterRosterElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachineRosterPackage.Literals.WARCASTER_ROSTER_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<WarjackRosterElement> getBattlegroup() {
		if (battlegroup == null) {
			battlegroup = new EObjectContainmentEList<WarjackRosterElement>(WarjackRosterElement.class, this, WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP);
		}
		return battlegroup;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public Warcaster getWarcaster() {
		return (Warcaster) getUnitType();
	}
	
	/**
	 * il pointValue di un Warcaster è uguale al suo pointCost 
	 * più il pointValue di tutti gli elementi del battlegroup
	 * attenzione: i punti extra del Warcaster possono essere spesi solo sul battlegroup
	 * @generated NOT
	 */
	@Override
	public int getPointValue() {
		int pointValue = getPointCost();
		for (RosterElement re: getBattlegroup()){
			pointValue += re.getPointValue();
		}
		return pointValue > 0?pointValue:0;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP:
				return ((InternalEList<?>)getBattlegroup()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP:
				return getBattlegroup();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP:
				getBattlegroup().clear();
				getBattlegroup().addAll((Collection<? extends WarjackRosterElement>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP:
				getBattlegroup().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachineRosterPackage.WARCASTER_ROSTER_ELEMENT__BATTLEGROUP:
				return battlegroup != null && !battlegroup.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //WarcasterRosterElementImpl
